var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');

const ENV = (process.env.NODE_ENV = process.env.ENV = 'production');

module.exports = webpackMerge(commonConfig, {
    // 代码映射
    devtool: 'inline-source-map', // 或 none

    output: {
        // 打包后的文件存放的地方
        path: helpers.root('dist'),
        publicPath: '/',
        // 打包后输出文件的文件名
        filename: '[name].[hash].js',
        chunkFilename: '[id].[hash].chunk.js'
    },

    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.optimize.UglifyJsPlugin({
            // https://github.com/angular/angular/issues/10618
            mangle: {
                keep_fnames: true
            }
        }),
        // 提取css样式
        new ExtractTextPlugin('[name].[hash].css'),
        // 定义环境变量
        new webpack.DefinePlugin({
            'process.env': {
                ENV: JSON.stringify(ENV)
            }
        }),
        new webpack.LoaderOptionsPlugin({
            htmlLoader: {
                minimize: false // workaround for ng2
            }
        })
    ],
    devServer: {
        // contentBase: "./dist", //本地服务器所加载的页面所在的目录
        historyApiFallback: true, //不跳转
        stats: 'minimal',
        hot: true,
        inline: true, //实时刷新
        port: 9090, // 修改端口，一般默认是8080
        proxy: {
            '/api': {
                target: 'http://localhost:8080',
                pathRewrite: { '^/api': '' }
            }
        }
    }
});